package com.itheima.test;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.Random;

public class MyJFrame1 extends JFrame implements MouseListener {


    //创建一个按钮对象
    JButton jbt1 = new JButton("点我啊");

    public MyJFrame1() {
        //设置界面的宽高
        this.setSize(608, 680);
        //设置界面的标题
        this.setTitle("拼图游戏单击版 v1.0");
        //设置界面置顶
        this.setAlwaysOnTop(true);
        //设置界面居中
        this.setLocationRelativeTo(null);
        //设置关闭模式
        this.setDefaultCloseOperation(3);
        //取消默认的居中放置
        this.setLayout(null);


        //给按钮设置位置和宽高
        jbt1.setBounds(0,0,100,50);

        //给按钮绑定监听器（动作）
        jbt1.addMouseListener(this);

        //将按钮添加到界面中
        this.getContentPane().add(jbt1);


        //设置显示出来，建议写在最后
        this.setVisible(true);
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        System.out.println("单击");
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println("按住不松");
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        System.out.println("松开");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        System.out.println("划入");
    }

    @Override
    public void mouseExited(MouseEvent e) {
        System.out.println("划出");
    }
}
